package com.sun.services.gateway.users;

import com.sun.commons.base.R;
import com.sun.services.roles.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
@Tag(name = "角色模块")
@AllArgsConstructor
public class RoleController {
    private final RoleService service;

    @GetMapping("/refreshPermissionCache")
    @Operation(summary = "刷新权限缓存")
    public R refreshPermissionCache(Long id) {
        return service.refreshPermissionCache(id);
    }

    @GetMapping("/getPermissionCache")
    @Operation(summary = "获取权限缓存")
    @PreAuthorize("hasRole('admin1') or hasAuthority('user:createUser')")
    public R getPermissionCache(String roleCode) {
        return R.ok().setData(service.getPermissionCache(roleCode));
    }
}
